package com.zzxx.mapper;


import com.zzxx.pojo.Role;
import org.apache.ibatis.annotations.Many;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface RoleMapper {
    @Select("select * from role")
    List<Role> getAllRoles();

    @Select("select * from role where id in (select roleId from users_role where userId = #{uid})")
    @Results(value = {
            @Result(id = true,column = "id",property = "id"),
            @Result(column = "roleName",property = "roleName"),
            @Result(column = "roleDesc",property = "roleDesc"),
            @Result(column = "id",property = "permissions",many = @Many(select = "com.zzxx.mapper.PermissionsMapper.findByRid")),
    })
    List<Role> findByUid(String uid);

    @Select("select * from role where id not in (select roleId from users_role where userId = #{uid})")
    List<Role> findNotByUid(String uid);
}
